package com.example.demo.datasource.rest;

import cn.hutool.core.util.ZipUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

/**
 * @author root
 * @date 2021-02-02 10:00
 */
@RestController
public class ExcelRest {

    @GetMapping("test")
    public void download(HttpServletResponse response, HttpServletRequest request) {
        try {
            File file = new File("d:/qr");
            File[] files = file.listFiles();
            if (null != files) {
                ZipUtil.zip(response.getOutputStream(), Charset.defaultCharset(), true, null, files);
            }
//            response.setCharacterEncoding("UTF-8");
//            response.setContentType("application/octet-stream;charset=UTF-8");
//            response.setHeader("Content-Disposition", "attachment;filename=qr.zip");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
